<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <script>
        var myarry = [{
            name: 'zhangsan',
            age: 20
        }, {
            name: 'lisi',
            age: 13
        }, {
            name: 'wangwu',
            age: 18
        }, {
            name: 'jake',
            age: 17
        }, {
            name: 'lisi',
            age: 24
        }]
        console.log(myarry[0]);

        // 传入数组和去重的key如name

        // function objectUnique1(arrObj, key) {
        //     var resultValue = []
        //     var resultObject = arrObj.filter((item, index) => {
        //         if (resultValue.indexOf(item[key]) == -1) {
        //             resultValue.push(item[key])
        //             return item
        //         }
        //         //用resultValue存放所有的key
        //     })
        //     return resultObject
        // }
        var result = objectUnique1(myarry, 'name')
        console.log(result)

        function objectUnique1(myarry, key) {
            let resultKey = [];
            let result = myarry.filter((item, index) => {
                if (resultKey.indexOf(item[key]) == -1) {
                    resultKey.push(item[key]);
                    return item;
                }
            })
            return result
        }
    </script>
</body>

</html>